package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;

import com.ruoyi.system.domain.dto.SupplierEnterpriseDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SupplierEnterprise;
import com.ruoyi.system.service.ISupplierEnterpriseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商对应企业关系Controller
 *
 * @author 协同
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/system/enterprise")
public class SupplierEnterpriseController extends BaseController {
    @Resource
    private ISupplierEnterpriseService supplierEnterpriseService;

    /**
     * 查询供应商对应企业关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SupplierEnterprise supplierEnterprise) {
        startPage();
        List<SupplierEnterprise> list = supplierEnterpriseService.selectSupplierEnterpriseList(supplierEnterprise);
        return getDataTable(list);
    }

    /**
     * 获取供应商对应企业关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(supplierEnterpriseService.selectSupplierEnterpriseById(id));
    }

    /**
     * 新增供应商对应企业关系
     */
    @PostMapping
    public AjaxResult add(@RequestBody SupplierEnterpriseDTO dto) {
        return AjaxResult.success(supplierEnterpriseService.insertSupplierEnterprise(dto));
    }

    /**
     * 修改供应商对应企业关系
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierEnterprise supplierEnterprise) {
        return toAjax(supplierEnterpriseService.updateSupplierEnterprise(supplierEnterprise));
    }

    /**
     * 删除供应商对应企业关系
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(supplierEnterpriseService.deleteSupplierEnterpriseByIds(ids));
    }
}
